using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Fieldbook.Entities;
using Fieldbook.DAL;
using System.Diagnostics;

namespace Fieldbook.NUnitTests.Fieldbook.DAL
{
    [TestFixture]
    public class FieldLeasingTest : DAOTest
    {
        [Test]
        public void AddFiledLeasingTest()
        {
            Exception exc = null;
            try
            {
                Appuser user = GetTestUser();
                AppuserDAO.InsertAppuser(user);
                Appuser user2 = GetTestUser();
                AppuserDAO.InsertAppuser(user2);
                Measureunit unit = GetTestMeasureUnit();
                unit.Categoryid = Measureunit.MeasureCategory.Area;
                MeasureunitDAO.InsertMeasureunit(unit);
                Field field = GetTestField();
                field.Measureunitid = (int)unit.Measureunitid;
                field.Ownerid = user.Userid;
                FieldDAO.InsertField(field);
                Fieldleasing filedLeasing = GetTestFieldLeasing();
                filedLeasing.Fieldid = field.Fieldid;
                filedLeasing.Leaseeid = user2.Userid;
                FieldleasingDAO.InsertFieldleasing(filedLeasing);

                Assert.IsNotNull(field.Fieldid);

                FieldleasingDAO.DeleteFieldleasing(filedLeasing);
                FieldDAO.DeleteField(field);
                MeasureunitDAO.DeleteMeasureunit(unit);
                AppuserDAO.DeleteAppuser(user);
                AppuserDAO.DeleteAppuser(user2);
            }
            catch (Exception ex)
            {
                Trace.Write(ex);
                exc = ex;
            }
            Assert.IsNull(exc);
        }
    }
}
